﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace wfimaging
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.openFileDialog1 = new OpenFileDialog();
            openFileDialog1.ShowDialog();
            this.pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.openFileDialog1 = new OpenFileDialog();
            openFileDialog1.ShowDialog();
            this.pictureBox2.Image = Image.FromFile(openFileDialog1.FileName);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Bitmap imgFrst = new Bitmap(pictureBox1.Image);
            Bitmap imgScnd = new Bitmap(pictureBox2.Image);
            int height = imgFrst.Height < imgScnd.Height ? imgFrst.Height : imgScnd.Height;
            int width = imgFrst.Width < imgScnd.Width ? imgFrst.Width : imgScnd.Width;
            Bitmap fussion=new Bitmap(width,height);
            for (int i = 0; i < fussion.Height; i++)
            {
                for (int j = 0; j < fussion.Width; j++)
                {
                    try
                    {
                        Color col1 = new Color();
                        Color col2 = new Color();
                        col1 = imgFrst.GetPixel(i, j);
                        col2 = imgScnd.GetPixel(i, j);
                        int R = 255, G = 255, B = 255;
                        if ((col1.R + col2.R) < Convert.ToByte(255))
                        {

                            R = (col1.R + col2.R) / 2;
                            G = (col1.G + col2.G) / 2;
                            B = (col1.B + col2.B) / 2;

                        }
                        Color col3 = Color.FromArgb(R, G, B);
                        fussion.SetPixel(i, j, col3);
                    }
                    catch
                    { }
                }
            }
            pictureBox3.Image = fussion;
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {

        }
    }
}
